using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.Rendering;
using UnityEngine;
// 动画控制器，管理所有动画播放
public class CharacterAnimation : MonoBehaviour
{
    public Animator animator;
    public CharacterState<PlayerController> currentState;
    public float VelocityY;
    public bool isAttack;

    private void Awake()
    {
        animator = GetComponent<Animator>();
    }
    void Update() { }
    //判断动画是否播放完毕
    public bool IsCurrentAnimFinished(string stateName, int layer = 0)
    {
        AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(layer);

        return stateInfo.IsName(stateName) && stateInfo.normalizedTime >= 1f && !animator.IsInTransition(layer);
    }
    internal void PlayMoveAnim()
    {
        animator.Play("move");

    }
    internal void PlayAttack(bool isattack)
    {
        isAttack = isattack;
        animator.SetTrigger("attack");
        animator.SetBool("isAttack", isAttack);
    }

    internal void PlayRightAttack1Anim()
    {
        // animator.Play("rightAttack");
    }

    internal void Die()
    {

        animator.Play("die");
    }
    internal void Hit()
    {
        animator.Play("hit");

    }

    internal void Idle()
    {
        animator.Play("idle");

    }
    internal void jumpAnim()
    {
        animator.Play("jump");
        animator.SetFloat("VelocityY", VelocityY);
    }

    public bool AnimationPlay0End(string animId)
    {
        AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
        return stateInfo.IsName(animId) && stateInfo.normalizedTime >= 1.0f;
    }
    public bool AnimationPlay1End(string animId)
    {
        int attackLayerIndex = animator.GetLayerIndex("Attack Layer");
        if (attackLayerIndex == -1) return false; // 层未找到
        AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(attackLayerIndex);
        return stateInfo.IsName(animId) && stateInfo.normalizedTime >= 1.0f;
    }
}
